package tata.servant;

import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;
import tata.GenericType;
import tata.StreamFacade;

import java.util.concurrent.TimeUnit;
@DubboService
public class StreamImpl implements StreamFacade {
    @Override
    public void serverStream(String request, StreamObserver<String> response) {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            response.onNext("test");
        }
        response.onCompleted();
    }
    @Override
    public void serverStreamGeneric(String request, StreamObserver<GenericType<String>> response) {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            GenericType<String> genericType = new GenericType();
            genericType.data = "call me da lao";
            response.onNext(genericType);
        }
        response.onCompleted();
    }
}
